function ref = gsfc_txf2(first, last, dataset)
global Project;
%prompt = {'Reference Channel', 'Window Size:', 'Window Overlap Size:', 'Length of FFT:           (number of points nfft)'};
%dlgTitle = 'Transfer Function Analysis Settings';
%lineNo = [1 30; 1 30; 1 30; 1 30];
%defAns = {'1', '2048', '1024', '2048'};
%settings = inputdlg(prompt, dlgTitle, lineNo, defAns);
%txf_Chan = str2num(settings{1,1});
%window = str2num(settings{2,1});
%noverlap = str2num(settings{3,1});
%nfft = str2num(settings{4,1});

load 'C:\Data\AppDefaults\DefaultSettings';
def_RefChan = num2str(Defaults{2,2}); % Input Reference Channel
prompt = {'Reference Channel'};
dlgTitle = 'Transfer Function Analysis Settings';
lineNo = [1 30];
defAns = {def_RefChan};
settings = inputdlg(prompt, dlgTitle, lineNo, defAns);
txf_Chan = str2num(settings{1,1}); % Reference Channel
SampleRate = Project.Test_Item.Run.Sample_Rate;
[freq_res, LFreq, UFreq] = Frequency_Parameters;

% Determine closest block size 2^n - to use FFT
n = ceil(log(SampleRate/freq_res)/log(2));
window = 2^n;
noverlap = (2^n)/2;
nfft = 2^n;
w = waitbar(0,'Please wait...');
ref = txf_Chan;
x = Project.Test_Item.Run.Channel(txf_Chan).Time_His(first:last);
for i = 1:Project.Test_Item.Run.Num_Chan
    y = Project.Test_Item.Run.Channel(i).Time_His(first:last);
    [Pxx, f] = tfe(x, y, nfft, SampleRate, [], noverlap);
    % Added 06-May-2005 by Chris McLeod
    if i == 1
        LFreqIndex = floor(LFreq / f(2)) + 1;
        UFreqIndex = floor(UFreq / f(2));
    end
    Project.Test_Item.Run.Channel(i).Analysis(dataset).Type = 3;
    Project.Test_Item.Run.Channel(i).Analysis(dataset).Abs = f(LFreqIndex:UFreqIndex)';
    Project.Test_Item.Run.Channel(i).Analysis(dataset).Ord = Pxx(LFreqIndex:UFreqIndex)';
    Project.Test_Item.Run.Channel(i).Analysis(dataset).FPoint = first;
    Project.Test_Item.Run.Channel(i).Analysis(dataset).LPoint = last;
	Project.Test_Item.Run.Channel(i).Analysis(dataset).RefChan = ref;
    waitbar(i/Project.Test_Item.Run.Num_Chan);
end
close(w);
